package com.ruoyi.zq.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.zq.domin.ZqNoticeDetails;
import com.ruoyi.zq.domin.vo.NoticeDetailsVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 * @Author: LoneyFeather
 * @Date: Created in 15:21 2021/12/30
 */
@Mapper
@Repository
public interface ZqNoticeDetailsMapper extends BaseMapper<ZqNoticeDetails> {



    @Select("<script>" +
            "select sys.notice_id, sys.notice_title, sys.notice_type, sys.notice_content, sys.status, sys.create_by, sys.create_time, \n" +
            "       zq.update_by, zq.update_time, zq.remark, zq.subscriber_id, zq.is_read, zq.is_del \n" +
            "from sys_notice sys \n" +
            "left join zq_notice_details zq on zq.notice_id = sys.notice_id \n" +
            "where ( zq.subscriber_id = 'ALL' \n" +
            "<if test = 'noticeVO.subscriberDeptId != null' >" +
            "        or zq.subscriber_id = #{noticeVO.subscriberDeptId} \n" +
            "</if> " +
            "<if test = 'noticeVO.subscriberUserId != null' >" +
            "        or zq.subscriber_id = #{noticeVO.subscriberUserId} \n" +
            "</if> " +
                ") and zq.is_del = 0 \n" +
            "<if test = 'noticeVO.isRead != null' > " +
                "and zq.is_read = #{noticeVO.isRead} \n" +
            "</if>" +
            "<if test = 'noticeVO.noticeId != null' > " +
                "and sys.notice_id = #{noticeVO.noticeId} \n" +
            "</if>" +
            "<if test = 'noticeVO.noticeType != null and noticeVO.noticeType != \"\" ' > " +
            "and sys.notice_type = #{noticeVO.noticeType} \n" +
            "</if>" +
            "<if test = 'noticeVO.status != null' > " +
                "and sys.status = #{noticeVO.status} \n" +
            "</if>" +
            " <if test = 'noticeVO.noticeTitle != null and noticeVO.noticeTitle != \"\"' >" +
                " and sys.notice_title LIKE concat('%',#{noticeVO.noticeTitle},'%') " +
            " </if>" +
            " <if test = 'noticeVO.createBy != null and noticeVO.createBy != \"\"' >" +
            " and sys.create_by LIKE concat('%',#{noticeVO.createBy},'%') " +
            " </if>" +
            "    order by sys.create_time desc " +
            "</script>")
    List<NoticeDetailsVO> selectByDTO(@Param("noticeVO") NoticeDetailsVO noticeVO);



    @Select("<script>\n" +
            "select sys.notice_id, sys.notice_title, sys.notice_type, sys.notice_content, sys.status, sys.create_by, sys.create_time,\n" +
            "       zq.update_by, zq.update_time, zq.remark, zq.subscriber_id, zq.is_read, zq.is_del \n" +
            "from sys_notice sys \n" +
            "left join zq_notice_details zq on sys.notice_id = zq.notice_id \n" +
            "where sys.notice_id = #{noticeId} \n " +
            "      and zq.is_del = 0 </script>")
    NoticeDetailsVO selectByNoticeId(@Param("noticeId") Long noticeId);


    @Delete("<script>" +
            "delete from zq_notice_details where notice_id = #{noticeId} " +
            "</script>")
    void removeByNoticeId(@Param("noticeId") Long noticeId);
}
